package model

import "simcard/utils"

type PrepaidCreateRequest struct {
	Id        int64  `json:"id"`
	PaymentId int64  `json:"payment_id"`
	EbikeId   int64  `json:"ebike_id"`
	Iccid     string `json:"iccid"`
	Sn        string `json:"sn"`
	Source    int    `json:"source"`
	Years     int    `json:"years"` // 预付费几年
}
type PrepaidUpdateRequest struct {
	Id            *int64  `json:"id"`
	PaymentId     *int64  `json:"payment_id"`
	EbikeId       *int64  `json:"ebike_id"`
	Sn            *string `json:"sn"`
	EffectiveDate *string `json:"effective_date"`
	ExpiredDate   *string `json:"expired_date"`
	Status        *int    `json:"status"`
	Source        *int    `json:"source"`
	CreatedAt     *int64  `json:"created_at"`
	UpdatedAt     *int64  `json:"updated_at"`
}
type PrepaidListRequest struct {
	Id            *int64  `json:"id"`
	Ids           []int64 `json:"ids"`
	PaymentId     *int64  `json:"payment_id"`
	EbikeId       *int64  `json:"ebike_id"`
	EbikeIds      []int64 `json:"ebike_ids"`
	Sn            *string `json:"sn"`
	EffectiveDate *string `json:"effective_date"`
	ExpiredDate   *string `json:"expired_date"`
	Status        *int    `json:"status"`
	Statuses      []int   `json:"statuses"`
	CreatedAt     *int64  `json:"created_at"`
	UpdatedAt     *int64  `json:"updated_at"`
	Index         int     `json:"index"`
	Size          int     `json:"size"`
}
type PrepaidListResponse struct {
	Total int            `json:"total"`
	List  []*PrepaidInfo `json:"list"`
}
type PrepaidInfoRequest struct {
	Id int64 `json:"id"`
}
type PrepaidInfo struct {
	Id            int64  `json:"id"`
	PaymentId     int64  `json:"payment_id"`
	EbikeId       int64  `json:"ebike_id"`
	Sn            string `json:"sn"`
	EffectiveDate string `json:"effective_date"`
	ExpiredDate   string `json:"expired_date"`
	Status        int    `json:"status"`
	Source        int    `json:"source"`
	CreatedAt     int64  `json:"created_at"`
	UpdatedAt     int64  `json:"updated_at"`
}
type PrepaidDeleteRequest struct {
	Id int64 `json:"id"`
}

type PrepaidCronRequest struct {
	Iccids []string `json:"iccids"`
	Ebikes []int64  `json:"ebikes"`
	Ids    []int64  `json:"ids"`
}

func (requestOpt *PrepaidCronRequest) ParseToPrepaidListRequest(req *PrepaidListRequest) *PrepaidListRequest {

	if len(requestOpt.Ebikes) > 0 {
		if len(requestOpt.Ebikes) == 1 {
			req.EbikeId = utils.GetValuePointer(requestOpt.Ebikes[0])
		} else {
			req.EbikeIds = requestOpt.Ebikes
		}
	}

	if len(requestOpt.Ids) > 0 {
		if len(requestOpt.Ids) == 1 {
			req.Id = utils.GetValuePointer(requestOpt.Ids[0])
		} else {
			req.Ids = requestOpt.Ids
		}
	}

	return req
}
